local zhijue = fk.CreateSkill {
  name = "lingling__zhijue",
}

Fk:loadTranslationTable{
  ["lingling__zhijue"] = "智绝",
  [":lingling__zhijue"] = "你可以将最后一张黑色手牌当任意普通锦囊牌使用（每回合每种牌名限一次），若当【无懈可击】使用则你摸一张牌。",

  ["#lingling__zhijue"] = "智绝：你可以将最后一张黑色手牌当任意普通锦囊牌使用",
}

zhijue:addEffect("viewas", {
  anim_type = "control",
  mute_card = false,
  pattern = ".|.|.|.|.|trick",
  prompt = "#lingling__zhijue",
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames("t")
    local names = player:getViewAsCardNames(zhijue.name, all_names, {}, player:getTableMark("lingling__zhijue-turn"))
    if #names > 0 then
      return UI.CardNameBox {choices = names, all_choices = all_names}
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    if self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcards(table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end))
    card.skillName = zhijue.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:addTableMark(player, "lingling__zhijue-turn", use.card.trueName)
    if use.card.trueName == "nullification" then
      player:drawCards(1, zhijue.name)
    end
  end,
  enabled_at_play = function (self, player)
    return #table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
    end) == 1
  end,
  enabled_at_response = function (self, player, response)
    if response then return end
    return #table.filter(player:getCardIds("h"), function(id)
      return Fk:getCardById(id).color == Card.Black
      end) == 1
  end,
  enabled_at_nullification = function (self, player, data)
    return not player:isKongcheng() and not table.contains(player:getTableMark("lingling__zhijue-turn"), "nullification")
  end,
})

zhijue:addAI(nil, "vs_skill")

return zhijue
